package com.hyh.prize.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyh.prize.entity.Acptsite;
import com.hyh.prize.service.AcptsiteService;
import com.lww.springcloudapi.result.Result;
import com.lww.springcloudapi.result.ResultCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.eclipse.jetty.util.StringUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/acpt/")
@Api(tags = "营业厅管理")
public class AcptsiteController {

    @Resource
    private AcptsiteService acptsiteService;

    @PostMapping("list/{current}/{limit}")
    @ApiOperation("查询营业厅信息，可通过地区查询")
    public Result getList(@PathVariable long current, @PathVariable long limit, String addressCode){

        Page page=acptsiteService.getlist(current,limit,addressCode);

        return Result.ok(page);
    }


    @GetMapping("get/{id}")
    @ApiOperation("根据id,查询营业厅的信息")
    public Result getById(@PathVariable long id){
        Acptsite byId = acptsiteService.getById(id);
        return Result.ok(byId);
    }

    @GetMapping("update")
    @ApiOperation("修改营业厅刮刮卡密码")
    public Result updagtePwd(Acptsite acptsite){
        Acptsite byId = acptsiteService.getById(acptsite.getId());
        boolean b=false;
        if(byId!=null){
            byId.setPassword(acptsite.getPassword());
            b = acptsiteService.updateById(byId);
        }

        if(b){
            return Result.ok();
        }
        return Result.fail();
    }

    @GetMapping("updateAll")
    @ApiOperation("修改营业厅刮刮卡密码")
    public Result updatePwdAll(String areaid,String pwd){
        QueryWrapper queryWrapper=new QueryWrapper();
        if(StringUtil.isEmpty(areaid) && StringUtil.isEmpty(pwd)){
            queryWrapper.eq("areaid",areaid);
            queryWrapper.eq("password",pwd);
            boolean update = acptsiteService.update(queryWrapper);
            return update?Result.ok():Result.fail();
        }

        return Result.build(null, ResultCodeEnum.PARAM_ERROR);
    }
}
